package com.game.battleship;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;

import com.game.battleship.adapters.HighScoresAdapter;
import com.game.battleship.db.DbAdapter;

public class HighScoresActivity extends Activity {

	ListView highScores_ListView;
	HighScoresAdapter adapter;
	DbAdapter dbAdapter;
	
	String[] usernames;
	int[] scores;
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.high_scores);
        
        dbAdapter = new DbAdapter(this);
        ArrayList<Map<String, String>> users = dbAdapter.getUsers();
        Iterator<Map<String, String>> ite = users.iterator();
        usernames = new String[users.size()];
        scores = new int[users.size()];
        int idx = 0;
        while (ite.hasNext()) {
        	Map<String, String> user = ite.next();
        	usernames[idx] = user.get("username");
        	scores[idx] = Integer.parseInt(user.get("score"));
        	idx++;
        }
        adapter = new HighScoresAdapter(this, usernames, scores);
        
        highScores_ListView = (ListView)this.findViewById(R.id.highScores_ListView);        
        highScores_ListView.setAdapter(adapter);
	}
}
